package webservice;

import java.sql.*;
import java.util.*;

import dal.*;
import model.*;

public class DocumentWS {

	private Connection _dbConn = null;

	private Connection getDbConnection() throws Exception {
		if (_dbConn == null) {
			_dbConn = ConnectionProvider.genConnection();
		}
		return _dbConn;
	}

	private GenericDal<DocumentModel, DocumentModelExt> _dal = null;

	private GenericDal<DocumentModel, DocumentModelExt> getDal()
			throws Exception {
		if (_dal == null) {
			Connection dbConn = getDbConnection();
			_dal = new GenericDal<DocumentModel, DocumentModelExt>(
					new DocumentModel(), dbConn);
		}
		return _dal;
	}

	public DocumentModel selectDocument(DocumentModel query)
 throws Exception {
		GenericDal<DocumentModel, DocumentModelExt> dal = getDal();
		DocumentModel model = (DocumentModel) dal.select(query);
		return model;
	}

	public DocumentModel[] selectListDocument(DocumentModelExt input)
			throws Exception {
		List<DocumentModel> models = _dal.selectList(input);
		DocumentModel[] result = (DocumentModel[]) models.toArray();
		return result;
	}

	public int deleteDocument(DocumentModel query) throws Exception {
		int result = _dal.delete(query);
		return result;
	}

	public int countDocument(DocumentModelExt input) throws Exception {
		int count = _dal.count(input);
		return count;
	}

}